import {
    defineStore
} from 'pinia'
import {
    getPathList,
    editPath
} from '../api/keyboardRomaing_request'

let frameRateMonitor = null
export const useStore = defineStore("store", { //添加了export
    state: () => {
        return {
            loginInfo: null, // 登录信息(用户信息，登录方式)
            showUi: true, // 隐藏所有ui, 点击 隐藏ui按钮 时触发
            showWindow: true, // 隐藏功能菜单，在点击功能弹窗的关闭键时置为false，点击任意功能菜单时置为true
            frameRate: null //  实时帧率
        }
    },
    actions: {
        getPathList(data) { //根据用户名获取对应键盘漫游
            return getPathList(data)
        },
        editPath(data) { //自定义键盘漫游键值
            return editPath(data)
        },
        initFrame() { // 帧率
            frameRateMonitor = Cesium.FrameRateMonitor.fromScene(viewer.scene);
            viewer.scene.postRender.addEventListener(this.postRender);
        },
        postRender() {
            this.frameRate = frameRateMonitor.lastFramesPerSecond ? Number(frameRateMonitor.lastFramesPerSecond).toFixed(2) : null
        },
        destroyFrame() {
            viewer.scene.postRender.removeEventListener(this.postRender);
            frameRateMonitor = null
        },
    }
})